use strict;
use Stdlog qw(:all);
use Test::More tests => 6;

our $stderr;
our $msg;

# Test 1 -- error
reset_stderr();
$msg = "This is a DEBUG message";
error($msg);
is($stderr, "$msg\n",
    "error");

# Test 2 -- notice
reset_stderr();
$msg = "This is a NOTICE message";
notice($msg);
is($stderr, "$msg\n",
    "notice");

# Test 3 -- info
reset_stderr();
$msg = "This is a INFO message";
info($msg);
isnt($stderr, "$msg\n",
    "info with \$verbose = 0");

# Test 4 -- info
reset_stderr();
$verbose = 1;
$msg = "This is a INFO message";
info($msg);
is($stderr, "$msg\n",
    "info with \$verbose = 1");


# Test 5 -- debug
reset_stderr();
$msg = "This is a DEBUG message";
debug($msg);
isnt($stderr, "$msg\n",
    "debug with \$debug = 0");

# Test 6 -- debug
reset_stderr();
$debug = 1;
$msg = "This is a DEBUG message";
debug($msg);
is($stderr, "$msg\n",
    "debug with \$debug = 1");








# close STDERR and redirect it to the $stderr string buffer
sub reset_stderr {
    $stderr = "";
    close STDERR;
    open STDERR, '>', \$stderr;
}